#ifndef C_DDCHAIN_H
#define C_DDCHAIN_H

#include "c_mem.h"
#include "c_define.h"

typedef struct dchain_head
{
	void *prev;
	void *next;
}DCHAIN_HEAD;

typedef struct dchain_type
{
	size_t data_size;
	void *dchain_head;
	void *dchain_tail;
	C_POOL data_pool;
	size_t dchain_length;
	void (*free_fun)(void* tag_data);
}C_DCHAIN;

#define dchain_Head(in_cur) ((DCHAIN_HEAD*)in_cur-1)

#define dchain_First(dchain) (((C_DCHAIN*)dchain)->dchain_head)

#define dchain_Tail(dchain) (((C_DCHAIN*)dchain)->dchain_tail)

#define dchain_Create(tag_dchain,data_size) (dchain_Create_Ex(tag_dchain,data_size,NULL))

C_DCHAIN* dchain_Create_Ex(C_DCHAIN *tag_dchain,size_t data_size,void (*free_fun)(void *tag_data));

void* dchain_Append(const void *in_data,C_DCHAIN *tag_dchain);

void* dchain_Insert(const void *in_data,void *in_cur,C_DCHAIN *tag_dchain);

#define dchain_Prev(in_cur) (dchain_Head(in_cur)->prev)
#define dchain_Next(in_cur) (dchain_Head(in_cur)->next)

void dchain_Remove(void *in_cur,C_DCHAIN *tag_dchain);

void dchain_Drop(C_DCHAIN *tag_dchain);

#endif
